@use "../_variables" as *;

.models-page {
  min-width: min-content;
  width: 100%;
  height: 100%;
}

.models-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  h1 {
    margin: 0;
    font-size: 28px;
  }

  @media (max-width: $breakpoint-xs) {
    width: fit-content;
  }
}

.models-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 30px;
  font-size: 20px;
  font-weight: 600;
  line-height: 36px;
}

.models-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  border-radius: 24px;
  border: 2px solid var(--stroke-gray-medium);
  overflow: hidden;

  .models-content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    font-size: 20px;
    gap: 20px;

    .left,
    .right {
      display: flex;
      align-items: center;
      gap: 12px;
      white-space: nowrap;
    }

    .left {
      fill: var(--text-medium);
    }

    .models-new-key-btn {
      background: var(--bg-dark);
      border: 2px solid var(--stroke-gray-medium);
      color: var(--text-invert);
      height: 40px;
      border-radius: 12px;
      font-size: 18px;
      line-height: 1;
      padding: 10px 12px;
      white-space: nowrap;
      transition: background $transition-fast ease-in-out;

      &:hover {
        background: var(--bg-gray-strong);
      }
    }

    .models-parameter-btn {
      background: transparent;
      border: 2px solid var(--stroke-gray-medium);
      height: 42px;
      border-radius: 12px;
      font-size: 20px;
      font-weight: 400;
      line-height: 20px;
      padding: 10px 20px;
      white-space: nowrap;
      cursor: pointer;
      transition: background $transition-fast ease-in-out;

      &:hover {
        background: var(--bg-gray-strong);
      }
    }
  }

  .providers-list {
    display: grid;
    grid-template-columns: 80px 3fr 4fr 2fr max-content 2fr 42px 20px;
    max-height: calc(100% - 82px);
    overflow-y: auto;

    @include scrollbar;

    &.oap-usage-limit {
      grid-template-columns: 80px 3fr 4fr max-content max-content 2fr 42px 20px;

      .providers-list-item {
        &.oap {
          > div {
            background: var(--bg-warning-weak);

            .providers-hint-item-text {
              color: var(--text-warning);
              font-size: 16px;
            }
          }
        }

        .provider-col-4 {
          min-width: 110px;
          padding-right: 10px;
        }

        .provider-col-5 {
          justify-content: flex-start;
          padding-right: 10px;
        }
      }
    }

    .providers-list-item {
      display: contents;
      font-size: 20px;

      &:hover {

        > div {
          background: var(--bg-pri-ultraweak);
        }
      }

      &.head {
        font-weight: 700;
        position: relative;

        > div {
          background: var(--bg-gray-medium);
          position: sticky;
          top: 0;
          z-index: 1;
        }
      }

      > div {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 20px 10px 20px 0;

        &.provider-col-1 {
        }

        &.provider-col-2 {
          display: flex;
          align-items: center;
          justify-content: flex-start;
          gap: 10px;

          .provider-name {
            @include line-clamp(1);

            user-select: none;
          }

          .provider-icon {
            width: 22px;
            height: 22px;
            filter: var(--filter-dark);

            &.no-filter {
              filter: none;
            }
          }
        }

        &.provider-col-3 {
          display: flex;
          flex-direction: row;
          align-items: center;
          justify-content: space-between;

          div {
            @include line-clamp(1);
          }

          .oap-level {
            font-weight: 700;
            color: var(--text-pri);
          }
        }

        &.provider-col-4 {
          min-width: 136px;
          padding-right: 36px;

          .models-popup-btn-container {
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;

            .models-unsupport-count-tooltip {
              position: absolute;
              right: -10px;
              top: 50%;
              transform: translate(100%, -50%);
              cursor: pointer;
            }
          }

          .models-popup-btn {
            padding: 1px 10px;
            border-radius: 12px;
            border: 2px solid var(--stroke-gray-medium);
            width: 100px;
            text-align: center;
            cursor: pointer;
            transition: background $transition-fast ease-in-out;

            &:hover {
              background: var(--bg-gray-strong);
            }
          }
        }

        &.provider-col-5 {
          justify-content: flex-start;
          padding-right: 0;
        }

        &.provider-col-6 {
        }

        &.provider-col-7 {
          padding-right: 0;
        }
      }

      .provider-edit-menu {
        width: 42px;
        height: 42px;
        padding: 2px;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        transition: opacity $transition-fast ease-in-out;

        &:hover,
        &[data-state="open"] {
          opacity: 1;
          background: var(--bg-gray-strong);
        }
      }

      &:hover {
        .provider-edit-menu {
          opacity: 1;
        }
      }
    }
  }

  button {
    &:disabled {
      opacity: 0.7;
      cursor: not-allowed;
    }

    &:focus {
      outline: none;
    }
  }
}

.models-parameter-popup-confirm {
  min-height: 700px;
  max-height: 750px;
  width: 900px;

  .popup-confirm-content {
    padding: 50px 60px 20px 60px;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
  }
}

.models-parameter-popup {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;

  .models-parameter {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
    justify-content: center;

    > label {
      font-size: 20px;
      font-weight: 700;
    }

    &:not(:first-child) {
      padding-top: 20px;
    }

    &:not(:last-child) {
      padding-bottom: 20px;
      border-bottom: 2px solid var(--stroke-gray-medium);
    }

    &.instructions {
      flex: 1;
    }

    .parameters-container {
      width: 100%;
      display: flex;
      gap: 50px;
      padding: 0 16px;
    }

    .parameter-label {
      display: flex;
      align-items: center;
      gap: 10px;
      cursor: default;
      font-size: 18px;
    }

    textarea {
      width: 100%;
      min-height: 120px;
      padding: 12px;
      border-radius: 6px;
      border: 1px solid var(--stroke-gray-medium);
      resize: none;
      font-size: 14px;
      line-height: 1.5;
      font-family: inherit;
      transition: all 0.3s ease;
      background: var(--bg-gray-medium);
      color: var(--text-strong);
      flex: 1;

      &::placeholder {
        color: var(--text-weak);
      }

      &:focus {
        outline: none;
        border-color: var(--stroke-pri-strong);
        box-shadow: 0 0 0 2px var(--sd-pri);
      }

      @include scrollbar;
    }
  }

  .instructions-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;

    .instructions-description {
      font-size: 16px;
      color: var(--text-weak);
    }
  }
}

.models-delete-confirm {
  .models-delete-confirm-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;

    .models-delete-confirm-title {
      font-size: 16px;
      font-weight: 700;
    }

    .models-delete-confirm-description {
      font-size: 16px;
      color: var(--text-weak);
    }
  }
}

.models-key-popup {
  width: 500px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 30px;
  height: 100%;

  &.edit{
    padding: 0 86px 0 62px;

    .title{
      font-weight: 700 !important;
      font-size: 20px;
      color: var(--text-medium);
      margin-bottom: 8px;
    }
  }

  .header {
    font-weight: 500;
    font-size: 24px;
    line-height: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-start;
    color: var(--text-strong);
    padding: 20px 0 36px 0;
    border-bottom: 1px solid var(--stroke-gray-medium);
  }

  .body{
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: auto;
    @include scrollbar;
  }

  .models-key-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    height: 100%;

    .models-key-field-title {
      font-weight: 700;
      color: var(--text-medium);
    }

    .warning-text {
      display: flex;
      align-items: center;
      gap: 12px;
      background-color: var(--bg-gray-weak);
      padding: 16px;
      border-radius: 8px;

      .warning-icon {
        color: var(--stroke-gray-medium);
      }

      .warning-text-description {
        font-size: 14px;
        color: var(--text-weak);
      }
    }

    .models-key-field-optional {
      display: flex;
      align-items: center;
      gap: 10px;
      color: var(--text-weak);
    }

    &:has(input[type="checkbox"]:checked) {
      .models-key-field-optional {
        color: var(--text-medium);
      }
    }
  }

  .models-key-field-description,
  .models-key-field-model-description {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-weak);
  }

  .parameter-value-input,
  select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid var(--stroke-gray-medium);
    transition: all $transition-fast;
    color: var(--text-medium);
    background: var(--bg-gray-weak);
    outline: none;

    &:focus {
      outline: none;
      border-color: var(--stroke-pri-strong);
    }
  }

  .error-message {
    color: var(--text-danger);
    font-size: 14px;
  }

  > .error-message {
    cursor: pointer;
    word-break: break-all;
  }
}

.model-popup {
  width: 900px;
  min-width: max-content;
  height: 65vh;

  .popup-confirm-content .loading-spinner {
    width: 50px;
    height: 50px;
  }

  .model-popup-content {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 12px;
    padding: 0 20px;
    height: 100%;
    width: 100%;

    .model-list-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 50px;

      .model-list-tools {
        display: flex;
        align-items: center;
        gap: 10px;
        justify-content: flex-end;

        .model-list-search {
          height: 100%;
          width: 220px;
          flex: 1;
          background: transparent;
          color: var(--text-strong);

          &:focus {
            outline: none;
          }

          .model-list-search-clear {
            width: 20px;
            height: 20px;
            cursor: pointer;
            background: var(--bg-gray-medium);
            border-radius: 50%;
            padding: 2px;

            &:hover {
              background: var(--bg-gray-strong);
            }
          }
        }

        .models-reload-btn {
          background: transparent;
          border: 1px solid var(--stroke-gray-medium);
          height: 40px;
          border-radius: 12px;
          align-content: center;
          font-size: 15px;
          font-weight: 400;
          line-height: 1;
          padding: 8px 10px;
          white-space: nowrap;
          cursor: pointer;
          transition: background $transition-fast ease-in-out;

          &:hover {
            background: var(--bg-gray-medium);
          }
        }

        .model-list-add-key {
          background: var(--bg-dark);
          border: 1px solid var(--stroke-gray-medium);
          height: 40px;
          color: var(--text-invert);
          border-radius: 12px;
          font-size: 15px;
          line-height: 1;
          padding: 8px 10px;
          white-space: nowrap;
          transition: background $transition-fast ease-in-out;

          &:hover {
            background: var(--bg-gray-strong);
          }
        }
      }
    }

    .model-list-title {
      display: flex;
      align-items: center;
      gap: 10px;
      justify-content: flex-start;
      height: 50px;
    }

    .model-list {
      display: flex;
      flex-direction: column;
      gap: 10px;
      flex: 1 1 0;
      overflow-y: auto;

      @include scrollbar;

      .loading-spinner-wrapper {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 1;

        .loading-spinner {
          width: 50px;
          height: 50px;
        }
      }

      .model-list-empty {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 1;
        font-size: 16px;
        color: var(--text-weak);
      }

      .model-option {
        display: flex;
        align-items: center;
        gap: 10px;
        justify-content: space-between;
        min-height: 65px;
        padding: 10px;
        border-radius: 12px;
        border: 2px solid var(--stroke-gray-medium);
        cursor: pointer;

        &.notSupportModel {
          .model-option-name {
            color: var(--text-weak);
          }
        }

        &:hover {
          background: var(--bg-gray-medium);
        }

        label {
          display: flex;
          align-items: center;
        }

        .model-option-name-wrapper {
          width: 100%;
          display: flex;
          align-items: center;
          justify-content: flex-start;
          gap: 18px;

          .model-option-name {

            @include line-clamp(1);
          }

          .model-option-name-hint {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 22px;
            height: 22px;
          }
        }

        .model-option-hint {
          display: flex;
          align-items: center;
          color: var(--text-weak);
          font-size: 14px;
          white-space: nowrap;
          gap: 18px;

          .correct-icon {
            color: var(--text-pri);
          }

          .verify-status {
            display: flex;
            align-items: center;
            gap: 5px;

            .loading-spinner {
              @include loading-spinner(16px, 2px);
              width: 22px;
              height: 22px;
            }
          }

          .model-option-verify-menu-wrapper {
            width: 30px;
            height: 30px;

            .model-option-verify-menu {
              opacity: 0;
              border-radius: 50%;
              width: 30px;
              height: 30px;
              padding: 6px;
              transition: opacity $transition-fast ease-in-out;
              color: var(--text-strong);

              &:hover,
              &[data-state="open"] {
                background: var(--bg-gray-strong);
              }

              &[data-state="open"] {
                opacity: 1;
              }
            }
          }
        }

        &:hover {
          .model-option-verify-menu-wrapper {
            .model-option-verify-menu {
              opacity: 1;
            }
          }
        }

        .verify-status-icon-wrapper {
          width: 20px;
          height: 20px;

          svg {
            color: var(--stroke-gray-medium);
            transition: all $transition-fast;
          }

          &.success-in-prompt {
            svg {
              color: var(--stroke-success);
            }
          }
        }

        .verify-status-text {
          display: flex;
        }

        .verify-status-error {
          display: flex;
          align-items: center;
          gap: 18px;

          svg {
            color: var(--stroke-danger);
          }

          .verify-status-error-btn {
            opacity: 0;
            color: var(--text-weak);
            cursor: pointer;
            &:hover {
              text-decoration: underline;
            }
          }
        }

        &:hover {
          .verify-status-error-btn {
            opacity: 1;
          }
        }
      }

      .model-option-verify-text {
        display: flex;
        flex-direction: column;
        gap: 5px;
        padding: 10px 10px 0 10px;
      }
    }

    .model-list-provider-filter {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;


      .model-list-provider-filter-left {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 10px;
      }

      .model-list-provider-filter-right {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        opacity: 0;
        transition: opacity $transition-fast ease-in-out;

        &.show {
          opacity: 1;
        }
      }

      .model-list-provider-filter-title {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 6px;
        color: var(--text-medium);

        svg {
          color: var(--text-medium);
        }
      }

      .model-list-provider-filter-list {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 6px;

        .provider-filter-item {
          display: flex;
          align-items: center;
          justify-content: center;
          padding: 6px 8px;
          border-radius: 6px;
          background: var(--bg-gray-medium);
          cursor: pointer;
          transition: background $transition-fast ease-in-out;
          position: relative;

          &::before {
            content: '';
            position: absolute;
            @include loading-skeleton(20px, 20px, 4px);
            opacity: 1;
            transition: opacity 0.2s ease-in-out;
          }

          &:has(.provider-filter-icon.loaded)::before {
            opacity: 0;
          }

          .provider-filter-icon {
            width: 20px;
            height: 20px;
            filter: var(--filter-dark);
            opacity: 0;
            transition: opacity 0.15s ease-in-out;

            &.loaded {
              opacity: 1;
            }

            &.no-filter {
              filter: none;
            }
          }

          &:hover {
            background: var(--bg-gray-strong);
          }

          &.active {
            background: var(--bg-pri-weak);
          }
        }
      }
    }
  }

  .models-progress-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    font-size: 12px;
    gap: 7.5px;

    .models-progress-text {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;

      .models-progress-text-right {
        display: flex;
        align-items: center;
        gap: 5px;

        .abort-button {
          cursor: pointer;
          display: flex;
          align-items: center;
          justify-content: center;
          color: var(--text-weak);
          border-radius: 50%;
          width: 20px;
          height: 20px;

          &:hover {
            color: var(--text-strong);
            background: var(--bg-gray-medium);
          }
        }
      }
    }

    .models-progress-container {
      width: 300px;
      height: 4px;
      background: var(--bg-gray-medium);
      border-radius: 4px;

      .models-progress {
        height: 100%;
        border-radius: 4px;
        background: var(--bg-pri-medium);
        transition: width 0.3s;
      }
    }
  }
}

.model-list-verify-popup {
  .popup-confirm-content {
    display: flex;
    flex-direction: column;

    .model-list-verify-title {
      font-size: 18px;
      margin: 18px 0;
    }

    .model-list-verify-desc {
      width: 100%;
      display: flex;
      flex-direction: column;
      color: var(--text-medium);

      .model-list-unverify-list {
        display: flex;
        flex-direction: column;
        align-items: center;

        span {
          color: var(--text-weak);
        }

        .model-list-unverify-ul-wrapper {
          width: 100%;
          display: flex;
          max-height: 240px;
          overflow-y: auto;

          @include scrollbar;

          ul {
            color: var(--text-weak);
            margin: 0;
            margin-top: 5px;
            padding-left: 20px;

            li {
              white-space: nowrap;
            }
          }
        }
      }
    }
  }
  .popup-confirm-footer {
    grid-template-columns: 1fr 2fr;
    display: grid;

    .popup-confirm-footer-hint {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: color $transition-fast ease-in-out;

      &:hover {
        color: var(--text-weak);
      }

      .verify-next-time-button {
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }

    .popup-confirm-footer-btn {
      button {
        flex: 1;
      }
    }
  }
}

.provider-edit-menu-item,
.model-option-verify-menu-item {
  display: flex;
  gap: 10px;

  img, svg {
    color: var(--text-weak);
  }
}

.api-key-input-wrapper {
  display: flex;
  align-items: center;
  position: relative;
  width: 100%;
}

.api-key-actions {
  position: absolute;
  right: -9px;
  transform: translateX(+100%);
  display: flex;
  gap: 8px;
  z-index: 10;
}

.icon-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;

  img{
    width: 20px;
    height: 20px;
  }

  &:hover{
    background: var(--bg-gray-medium);
  }
}

.model-list-unsupport-info {
  .popup-confirm-content {
    position: relative;
  }

  .model-list-unsupport-info-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;

    .model-list-unsupport-info-title {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 10px;

      svg {
        width: 16px;
        height: 16px;
        color: var(--stroke-danger);
      }
    }

    .model-list-unsupport-info-content {
      display: flex;
      justify-content: flex-start;
      color: var(--text-weak);
      max-height: 360px;
      overflow-y: auto;
      @include scrollbar;
    }

    .model-list-unsupport-info-copy {
      position: absolute;
      right: 16px;
      bottom: 0;
      cursor: pointer;

      svg {
        color: var(--text-weak);
      }
    }
  }

  .popup-confirm-footer.center {
    .popup-confirm-footer-btn {
      width: fit-content;
    }
  }
}

.model-option-description-tooltip {
  max-width: 530px;

  .model-option-description {
    width: 100%;
    color: var(--text-medium);

    .model-option-description-header {
      display: flex;
      flex-direction: column;
      gap: 8px;
      margin-bottom: 20px;

      .header-row {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        color: var(--text-medium);

        .title-section {
          display: flex;
          justify-content: space-between;
          align-items: center;
          gap: 12px;
          width: 100%;
          flex: 1;

          .model-option-description-name-wrapper {
            display: flex;
            align-items: center;
            gap: 5px;

            .model-option-description-name {
              font-size: 20px;
              font-weight: 700;
              line-height: 1.2;

              @include line-clamp(2);
            }

            .oap-model-icon {
              width: 24px;
              height: 24px;
              filter: var(--filter-dark);

              &.no-filter {
                filter: none;
              }
            }
          }

          .oap-store-link {
            display: flex;
            align-items: center;
            justify-content: center;
            border: none;
            background: none;
            padding: 0;
            color: var(--text-medium);
            padding: 4px;
            border-radius: 50%;

            &:hover {
              background-color: var(--bg-gray-medium);
              color: var(--text-strong);
            }

            &:focus {
              outline: none;
            }
          }
        }

        .model-option-description-cost {
          font-size: 14px;
          font-weight: 500;
          color: var(--text-weak);
        }

        .model-option-description-feature {
          font-size: 16px;
          font-weight: 700;
          line-height: 1.5;

          @include line-clamp(2);
        }
      }
    }

    .model-option-description-special {
      margin-top: 16px;
      border: 1px solid var(--stroke-gray-medium);
      border-radius: 3px;
      padding: 12px 7px;
      max-height: 170px;
      overflow-y: auto;

      @include scrollbar;

      ul {
        padding: 0;
        padding-left: 20px;
        margin: 0;

        li {
          margin-bottom: 5px;
          font-size: 13px;
        }
      }
    }
  }
}

.model-customID-popup {
  .model-popup-content{
    width: 100%;
  }
}